﻿using System.Xml.Linq;
using Engine;
using Game;

namespace SCIENEW
{
	public class SpinnerWidget : CanvasWidget
	{
		public GridPanelWidget m_inventoryGrid;

		public InventorySlotWidget m_resultSlot;

		public InventorySlotWidget rawSlot;

		public ValueBarWidget m_progress;

		public ComponentSpinner m_kibbler;

		public SpinnerWidget(IInventory inventory, ComponentSpinner furnace)
		{
			m_kibbler = furnace;
			XElement node = ContentManager.Get<XElement>("Widgets/SpinnerWidget");
			LoadContents(this, node);
			m_inventoryGrid = Children.Find<GridPanelWidget>("InventoryGrid");
			m_progress = Children.Find<ValueBarWidget>("Progress");
			m_resultSlot = Children.Find<InventorySlotWidget>("ResultSlot");
			rawSlot = Children.Find<InventorySlotWidget>("RawSlot");
			int num = 10;
			for (int i = 0; i < m_inventoryGrid.RowsCount; i++)
			{
				for (int j = 0; j < m_inventoryGrid.ColumnsCount; j++)
				{
					var inventorySlotWidget = new InventorySlotWidget();
					inventorySlotWidget.AssignInventorySlot(inventory, num++);
					m_inventoryGrid.Children.Add(inventorySlotWidget);
					m_inventoryGrid.SetWidgetCell(inventorySlotWidget, new Point2(j, i));
				}
			}
			rawSlot.AssignInventorySlot(m_kibbler, 0);
			m_resultSlot.AssignInventorySlot(m_kibbler, 1);
		}

		public override void Update()
		{
			//m_fire.ParticlesPerSecond = (m_componentFurnace.HeatLevel > 0f) ? 24 : 0;
			m_progress.Value = m_kibbler.CraftingProgress;
			if (!m_kibbler.IsAddedToProject)
			{
				ParentWidget.Children.Remove(this);
			}
		}
	}
}